package com.example.r2022913.service.WxService.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.r2022913.model.dao.WxDao.AdminMailDao;
import com.example.r2022913.model.entity.WxEntity.AdminUserMailEntity;
import com.example.r2022913.service.WxService.AdminMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;

@Service
public class AdminMailServiceImpl extends ServiceImpl<AdminMailDao, AdminUserMailEntity> implements AdminMailService {
    @Autowired
    AdminMailDao adminmailDao;

    @Override
    public IPage adminMailList(Integer pageNum, Integer pageSize, Map<String, Object> params,String openId) {
        QueryWrapper<AdminUserMailEntity> queryWrapper = new QueryWrapper<>();
        //拿出参数关键字openid,用户唯一id
        if (openId!=null){
            queryWrapper.eq("open_id",openId);
            //意见类型
            String typeName = (String) params.get("typeName");
            //模糊查询管理员邮箱
            if (StringUtils.hasText(typeName)){
                queryWrapper.eq("type_name",typeName);
            }

            //意见部门
            String departmentName = (String) params.get("departmentName");
            //模糊查询管理员邮箱
            if (StringUtils.hasText(departmentName)){
                queryWrapper.eq("department_name",departmentName);
            }
            Page pageWc = new Page(pageNum,pageSize);
            IPage<AdminUserMailEntity> page=this.page(pageWc,queryWrapper);
            return page;
        }
        return null;
    }

    @Override
    public AdminUserMailEntity adminMailById(Long adminId) {
        return adminmailDao.selectById(adminId);
    }

    @Override
    public Integer adminMailCount(String openId) {
        QueryWrapper<AdminUserMailEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("open_id",openId);
        return adminmailDao.selectCount(queryWrapper);
    }

    @Override
    public int adminMailAdd(AdminUserMailEntity adminUserMailEntity){
        return adminmailDao.insert(adminUserMailEntity);
    }

}
